import req from "@/api/req.js";
import msg from "@/zdpui/util/msg.js";

// 分页查询用户
const getPage = async (page, size) => {
    let data = {}
    const params = {page, size}
    await req.get("/user/page", params)
        .then(res => data = res)
    return data
}

// 新增用户
const add = async (username, password) => {
    let body = {username, password}
    await req.post("/user/register", body)
        .then(res => msg.success("添加用户成功"))
}

// 修改用户
const update = async (id, username, password) => {
    let body = {username, password}
    await req.put(`/user/${id}`, body)
        .then(res => msg.success("修改用户成功"))
}

// 删除用户
const del = async (id) => {
    await req.delete(`/user/${id}`)
        .then(res => msg.success("删除用户成功"))
}

// 导出
export default {
    getPage,
    add,
    update,
    del,
}